#!/usr/bin/python3
''' 娱乐类脚本， 利用python，实现以下menu 函数的功能'''
import os

song = ["十年", "我的好兄弟", "翻滚吧，蛋炒饭"]
singer = ["汪涵", "baby", "张杰"]


def menu():
    os.system("clear")
    print("\t\t\t\t1.增加歌手")
    print("\t\t\t\t2.显示歌手名单")
    print("\t\t\t\t3.删除歌手")
    print("\t\t\t\t4.显示歌库")
    print("\t\t\t\t5.删除歌曲")
    print("\t\t\t\t6.增加歌曲")
    print("\t\t\t\t7.统计歌手及歌曲")
    print("\t\t\t\t8.查询歌手是否在名单中")
    print("\t\t\t\t9.查询歌曲是否存在于歌单中")
    print("\t\t\t\t0.退出菜单")


def del_singer():
    print("exist singer is:")
    print(*singer)
    d_singer = input("who do you want to delete(press 0 to exist):")
    if d_singer == "0":
        return
    if d_singer in singer:
        singer.remove(d_singer)
        print("del %s success,after del exist singer have:" % d_singer)
        print(*singer)
        tmp = input("please input key enter to continue")
    else:
        print("%s not in singer name,please try again")
        del_singer()


def del_song():
    print("exist song is:")
    print(*song)
    d_song = input("which song do you want to delete(press 0 to exist):")
    if d_song == "0":
        return
    if d_song in song:
        song.remove(d_song)
        print("del %s success,after del exist singer have:" % d_song)
        print(*song)
        tmp = input("please input key enter to continue")
    else:
        print("%s not in singer name,please try again" % d_song)
        del_song()


def add_singer():
    print("exist singer is:")
    print(*singer)
    insert_singer = input("who do you want to add:")
    if insert_singer not in singer:
        singer.append(insert_singer)
        print("add singer %s success" % insert_singer)
        print("after add the singer have:")
        print(*singer)
    else:
        print("the singer was exist ,can not add him,please try another!")
        add_singer()
    tmp = input("please input key enter to continue")


def add_song():
    print("exist song is:")
    print(*song)
    insert_song = input("which song do you want to add:")
    if insert_song not in song:
        song.append(insert_song)
        print("add song %s success" % insert_song)
        print("after add the song have:")
        print(*song)
    else:
        print("the song was exist ,can not add it,please try another!")
        add_song()
    tmp = input("please input key enter to continue")


def search_singer():
    s_singer = input("which singer do want to search:")
    if s_singer in singer:
        print("singer %s was in " % s_singer)
    else:
        print("singer %s not in " % s_singer)


def search_song():
    s_song = input("which singer do want to search:")
    if s_song in song:
        print("song %s was in " % s_song)
    else:
        print("song %s not in " % s_song)


def main():
    while True:
        menu()
        choice = input("请输入你要使用的功能：")
        # print(choice)
        if choice == "1":
            add_singer()
            continue
        elif choice == "2":
            print("歌手名单为：")
            print(*singer)
            tmp = input("please input key enter to continue")
            continue
        elif choice == "3":
            del_singer()
            continue
        elif choice == "4":
            print("歌曲名单为：")
            print(*song)
            tmp = input("please input key enter to continue")
            continue
        elif choice == "5":
            del_song()
            continue
        elif choice == "6":
            add_song()
            continue
        elif choice == "7":
            print("there are %d singers!" % len(singer))
            print("there are %d songs!" % len(song))
            tmp = input("please input key enter to continue")
            continue
        elif choice == "8":
            search_singer()
            tmp = input("please input key enter to continue")
            continue
        elif choice == "9":
            search_song()
            tmp = input("please input key enter to continue")
            continue
        elif choice == "0":
            print("good bye")
            exit()


main()
